package javabasic.threads.CreateThreadMethods;

import java.util.concurrent.*;

public class PoolMethod {
    public static void main(String[] args) {
        MyThread4 myThread4 = new MyThread4();
        ExecutorService threadPool = Executors.newCachedThreadPool();
        Future future = threadPool.submit(myThread4);
        while (!future.isDone()){
            System.out.println("子线程未执行完毕，请等待。。。。。");
        }
        System.out.println("主线程监控子线程已执行完毕");
        try {
            System.out.println(future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        threadPool.shutdown();
    }
}

class MyThread4 implements Callable{
    private String str="pool method";
    @Override
    public Object call() throws Exception {
        System.out.println("子线程准备执行");
        Thread.sleep(200);
        System.out.println("子线程执行完毕");
        return str;
    }
}


